package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2019/4/16 16:33
 * 修改备注：
 * ================================================
 */
public class BusinessAgr {
    /**
     * 获取新农技类型
     *
     * @param activity
     * @param handler
     */
    public static void getNewAgrType(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_GET_NEW_AGR_TYPE, "", params, handler, MSG.MSG_GET_NEW_AGR_TYPE_SUCCESS, MSG.MSG_GET_NEW_AGR_TYPE_FIELD);

    }


    /**
     * 获取新农艺列表
     *
     * @param activity
     * @param firstTypeCode     一级类目code
     * @param secondTypeId      二级类目id
     * @param farmOperationId   农事操作id
     * @param productStandardId 生产标准id
     * @param handler
     */
    public static void getNewAgrList(Activity activity, String firstTypeCode, String secondTypeId, String farmOperationId,
                                     String productStandardId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("firstTypeCode", firstTypeCode);
        params.put("secondTypeId", secondTypeId);
        params.put("farmOperationId", farmOperationId);
        params.put("productStandardId", productStandardId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_NEW_AGR_LIST, "", params, handler, MSG.MSG_GET_NEW_AGR_LIST_SUCCESS, MSG.MSG_GET_NEW_AGR_LIST_FIELD);

    }

    public static void getNewAgrListV2(Activity activity, String secondTypeId,
                                     String productStandardId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("secondTypeId", secondTypeId);
        params.put("productStandardId", productStandardId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_NEW_AGR_LIST_V2, "", params, handler, MSG.MSG_GET_NEW_AGR_LIST_SUCCESS, MSG.MSG_GET_NEW_AGR_LIST_FIELD);

    }


    /**
     * 搜索新农艺
     *
     * @param activity
     * @param searchContent     搜索内容
     * @param farmOperationId
     * @param productStandardId
     * @param page
     * @param limit
     * @param handler
     */
    public static void searchNewAgr(Activity activity, String searchContent, String farmOperationId,
                                    String productStandardId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("searchContent", searchContent);
        params.put("farmOperationId", farmOperationId);
        params.put("productStandardId", productStandardId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_SEARCH_NEW_AGR, "", params, handler, MSG.MSG_SEARCH_NEW_AGR_SUCCESS, MSG.MSG_SEARCH_NEW_AGR_FIELD);

    }
    public static void searchNewAgrV2(Activity activity, String searchContent,
                                    String productStandardId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("searchContent", searchContent);
        params.put("productStandardId", productStandardId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_SEARCH_NEW_AGR_V2, "", params, handler, MSG.MSG_SEARCH_NEW_AGR_SUCCESS, MSG.MSG_SEARCH_NEW_AGR_FIELD);

    }


    /**
     * 获取病虫草害列表
     *
     * @param activity
     * @param typeCode          病虫草害类型code 病害-bcch_bh  虫害-bcch_ch
     * @param farmOperationId
     * @param productStandardId
     * @param handler
     */
    public static void getPestList(Activity activity, String typeCode, String farmOperationId,
                                   String productStandardId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("typeCode", typeCode);
        params.put("farmOperationId", farmOperationId);
        params.put("productStandardId", productStandardId);

        OkHttpUtil.post(activity, URL.URL_GET_PEST_LIST, "", params, handler, MSG.MSG_GET_PEST_LIST_SUCCESS, MSG.MSG_GET_PEST_LIST_FIELD);

    }

    /**
     * 获取病虫草害详情
     *
     * @param activity
     * @param diseasePestId 病虫草害id
     * @param handler
     */
    public static void getPestDetail(Activity activity, String diseasePestId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("diseasePestId", diseasePestId);

        OkHttpUtil.post(activity, URL.URL_GET_PEST_DETAIL, "", params, handler, MSG.MSG_GET_PEST_DETAIL_SUCCESS, MSG.MSG_GET_PEST_DETAIL_FIELD);

    }

    /**
     * 经验交流列表
     *
     * @param activity
     * @param disPestsWeedsId 病虫草害ID  为空时查询自己
     * @param page
     * @param limit
     * @param handler
     */
    public static void experienceList(Activity activity, String disPestsWeedsId, int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("disPestsWeedsId", disPestsWeedsId);
        if (disPestsWeedsId.equals(""))
            params.put("userAccId", UserXML.getUserId(activity));
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_EXPERIENCE_LIST, "", params, handler, MSG.MSG_EXPERIENCE_LIST_SUCCESS, MSG.MSG_EXPERIENCE_LIST_FIELD);

    }


    /**
     * 经验保存/经验修改
     *
     * @param activity
     * @param id                   经验ID 修改时必传
     * @param title                标题
     * @param controlMethod        防治方法
     * @param img                  图片
     * @param geographicalPosition 地址位置
     * @param disPestsWeedsId      病虫草害ID
     * @param handler
     */
    public static void saveExperience(Activity activity, String id, String title, String controlMethod, String img, String geographicalPosition, String disPestsWeedsId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", id);
        params.put("title", title);
        params.put("controlMethod", controlMethod);
        params.put("img", img);
        params.put("geographicalPosition", geographicalPosition);
        params.put("disPestsWeedsId", disPestsWeedsId);
        params.put("userAccId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_SAVE_EXPERIENCE, "", params, handler, MSG.MSG_SAVE_EXPERIENCE_SUCCESS, MSG.MSG_SAVE_EXPERIENCE_FIELD);

    }


    /**
     * 删除经验
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void deleteExperience(Activity activity, String id, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", id);

        OkHttpUtil.post(activity, URL.URL_DELETE_EXPERIENCE, "", params, handler, MSG.MSG_DEL_EXPERIENCE_SUCCESS, MSG.MSG_DEL_EXPERIENCE_FIELD);

    }

    /**
     * 经验详情
     *
     * @param activity
     * @param id
     * @param handler
     */
    public static void experienceDetail(Activity activity, String id, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", id);

        OkHttpUtil.post(activity, URL.URL_EXPERIENCE_DETAIL, "请稍等", params, handler, MSG.MSG_EXPERIENCE_DETAIL_SUCCESS, MSG.MSG_EXPERIENCE_DETAIL_FIELD);

    }
}
